package cn.cloud.search.server.query_creater.impl;

import org.apache.log4j.Logger;
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.BooleanClause.Occur;

import cn.cloud.search.bean.query.QueryRequestInfo;
import cn.cloud.search.server.query_creater.IDomainQueryCreator;
import cn.cloud.search.server.query_creater.IFieldQueryCreator;
import cn.cloud.search.server.query_creater.IQueryCreator;

public class QueryCreator implements IQueryCreator {
	
	private static final Logger log = Logger.getLogger(QueryCreator.class);
	
	private IDomainQueryCreator dqc;
	
	private IFieldQueryCreator fqc;
	
	

	public IDomainQueryCreator getDqc() {
		return dqc;
	}



	public void setDqc(IDomainQueryCreator dqc) {
		this.dqc = dqc;
	}



	public IFieldQueryCreator getFqc() {
		return fqc;
	}



	public void setFqc(IFieldQueryCreator fqc) {
		this.fqc = fqc;
	}



	public Query createrQuery(QueryRequestInfo qri) {
		// TODO Auto-generated method stub
		BooleanQuery q = new BooleanQuery();
		if(!qri.getQueryType().toUpperCase().equals(QueryRequestInfo.ALL_TYPE)){
			Query q_type = dqc.creator(qri.getQueryType());
			q.add(q_type,Occur.MUST);
		}
		
		Query q_content = fqc.creater(qri.getQueryContent(), qri.getQueryType());
		q.add(q_content,Occur.MUST);
		return q;
	}

}
